<?php
/**
 * create breadcrumbs
 *
 * @author kim
 * @return string
 */
class App_View_Helper_Nav extends Zend_View_Helper_Abstract
{
    /**
     * get the breadcrumbs string
     *
     * @param string $breadCrumbs
     * @param null|string $controller
     * @param null|string $action
     * @return string
     */
    public function nav($breadCrumbs = '', $controller = null, $action = null)
    {
        // find current controller and action
        if (is_null($controller)) {
            $controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
        }
        if (is_null($action)) {
            $action = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
        }

        // find page
        if ($page = $this->view->navigation()->findOneBy('controller', $controller)) {
            if (!empty($breadCrumbs) and is_string($breadCrumbs)) {
                // add pages
                $page->addPage(array(
                    'controller' => $controller,
                    'action' => $action,
                    'label' => $breadCrumbs,
                ));
            }
        }

        // render breadcrumbs
        $nav = $this->view->navigation()
                          ->breadcrumbs()
                          ->setLinkLast(false)
                          ->setMinDepth(0)
                          ->render();

        return $nav;
    }

}
